//
//  MKTChatTextBubbleView.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2021/7/8.
//  Copyright © 2021 moon. All rights reserved.
//

#import "MKTChatTextBubbleView.h"

@implementation MKTChatTextBubbleView
- (id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.clipsToBounds = YES;
        self.layer.cornerRadius = 5;
        
        self.contentInsets = UIEdgeInsetsMake(15, 15, 15, 15);
        self.bgView = [[UIImageView alloc] init];
        self.bgView.contentMode = UIViewContentModeScaleToFill;
        self.bgView.backgroundColor = [UIColor colorWithRed:0 green:0.5 blue:1 alpha:1];
        [self addSubview:self.bgView];
        //
        self.textLabel = [[UILabel alloc] init];
        self.textLabel.numberOfLines = 0;
        self.textLabel.textColor = [UIColor whiteColor];
        self.textLabel.font = [UIFont systemFontOfSize:14];
        self.textLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:self.textLabel];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGRect bounds = self.bounds;
    //
    self.bgView.frame = bounds;
    //
    UIEdgeInsets insets = self.contentInsets;
    CGRect f1 = UIEdgeInsetsInsetRect(bounds, insets);
    self.textLabel.frame = f1;
}
- (CGSize)sizeThatFits:(CGSize)size{
    UIEdgeInsets insets = self.contentInsets;
    CGSize s = CGSizeZero;
    CGSize fitsize = [self.textLabel sizeThatFits:CGSizeMake(size.width-insets.left-insets.right, 9999999999)];
    
    s.width = fitsize.width+insets.left+insets.right;
    s.height = fitsize.height+insets.top+insets.bottom;
    if(self.fixWidth){
        s.width = size.width;
    }
    return s;
}
@end

@implementation MKTChatTextBubbleViewMine
- (id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.contentInsets = UIEdgeInsetsMake(15, 16, 15, 15);
        self.bgView.backgroundColor = [UIColor colorWithRed:0 green:0.5 blue:1 alpha:1];
    }
    return self;
}
@end
@implementation MKTChatTextBubbleViewOther
- (id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.contentInsets = UIEdgeInsetsMake(15, 15, 15, 16);
        self.bgView.backgroundColor = [UIColor grayColor];
    }
    return self;
}
@end
